/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package login.vista;


import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import login.LoginHostal;
import login.modelo.Controlador;

/**
 *
 * @author nahe
 */
public class LoginController implements Initializable {
    
    @FXML
    private Label label;
    @FXML
    private TextField usuario;
    @FXML
    private PasswordField contraseña;
    @FXML
    private LoginHostal application;
    
    @FXML
    private void handleButtonAction(ActionEvent event) {
        boolean result= Controlador.obtenerInstancia().verificarAutentificacion(usuario.getText(), contraseña.getText());
        if(result){
            
            application.loadSuccessLoginScene();
        }else{
            
            application.loadFailLoginScene();
        }
        
    }
        @FXML
    private void handleKeyPressedLogin(KeyEvent event) {
        if(event.getCode()== KeyCode.ENTER){
            boolean result= Controlador.obtenerInstancia().verificarAutentificacion(usuario.getText(), contraseña.getText());
            if(result){

                application.loadSuccessLoginScene();
            }else{

                application.loadFailLoginScene();
            }
        
        }
    }
    @Override
    public void initialize(URL url, ResourceBundle rb) {
    }
    
    public void setApp(LoginHostal aThis){
        this.application = aThis;
    }
}
